package com.example.xmpic.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.common.base.OnCallBackToRefresh;
import com.example.xmpic.R;
import com.example.xmpic.R2;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author skygge
 * @date 2020-01-25.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：截图预览
 */
public class BaseImageDialog extends Dialog {

    @BindView(R2.id.iv_dialog_image)
    ImageView mImage;
    @BindView(R2.id.tv_dialog_cancel)
    TextView tvDialogCancel;
    @BindView(R2.id.tv_dialog_confirm)
    TextView tvDialogConfirm;

    private Bitmap mBitmap;
    private String mCancel;
    private String mConfirm;
    private OnCallBackToRefresh mCallBack;

    public BaseImageDialog(Context context, OnCallBackToRefresh callBack) {
        super(context, R.style.window_background2);
        this.mCallBack = callBack;
    }

    public void setImageAndButton(Bitmap bitmap, String cancel, String confirm) {
        this.mBitmap = bitmap;
        this.mConfirm = confirm;
        this.mCancel = cancel;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_image);
        setCanceledOnTouchOutside(false);
        ButterKnife.bind(this);

        mImage.setImageBitmap(mBitmap);
        tvDialogConfirm.setText(mConfirm);
        tvDialogCancel.setText(mCancel);

        tvDialogConfirm.setOnClickListener(v -> {
            mCallBack.onConfirm();
            dismiss();
        });

        tvDialogCancel.setOnClickListener(v -> {
            mCallBack.onCancel();
            dismiss();
        });
    }


}
